package wsi.input;

import org.json.JSONArray;
import org.rygh.semantic.model.rdf.Entity;

public class InputFileTuple implements Comparable<InputFileTuple> {
	private final int degree;

	private final Entity entity;
	private final String value;

	public InputFileTuple(Entity entity, String value, int degree) {
		this.entity = entity;
		this.value = value;
		this.degree = degree;
	}

	public InputFileTuple(JSONArray ja) {
		int len = ja.length();

		if (len == 2) {
			degree = -1;
			value = ja.getString(0);
			entity = new Entity(ja.getString(1), false);
		} else {
			degree = ja.getInt(0);
			value = ja.getString(1);
			entity = new Entity(ja.getString(2), false);
		}
	}

	@Override
	public int compareTo(InputFileTuple o) {
		return o.degree - degree;
	}

	public int getDegree() {
		return degree;
	}

	public Entity getEntity() {
		return entity;
	}

	public JSONArray getJsonArray() {
		JSONArray ja = new JSONArray();

		if (degree > 0)
			ja.put(degree);

		ja.put(value);
		ja.put(entity.getValue());

		return ja;
	}

	public String getValue() {
		return value;
	}

	public String toJsonString() {
		return getJsonArray().toString();
	}

}
